#include "stdafx.h"
#include "TimeSpan.h"

namespace Core
{
	TimeSpan::TimeSpan()
	{
		Tick();
	}

	float TimeSpan::Peek()
	{
		timeb t_Now;
		ftime(&t_Now);
		return ((float)(t_Now.time-m_Time.time) + (float)(t_Now.millitm-m_Time.millitm)/1000);
	}

	float TimeSpan::Tick()
	{
		timeb t_Last = m_Time;
		ftime(&m_Time);
		return ((float)(m_Time.time-t_Last.time) + (float)(m_Time.millitm-t_Last.millitm)/1000);
	}

	float TimeSpan::Delta(TimeSpan p_TimeSpan)
	{
		return ((float)(GetSecond()-p_TimeSpan.GetSecond()) + (float)(GetMilliSecond()-p_TimeSpan.GetMilliSecond())/1000);
	}

	void TimeSpan::GetTime(unsigned long& p_Seconds, unsigned short& p_MilliSeconds)
	{
		p_Seconds = (unsigned long)m_Time.time;
		p_MilliSeconds = m_Time.millitm;
	}

	unsigned long TimeSpan::GetSecond()
	{
		return (unsigned long)m_Time.time;
	}

	unsigned short TimeSpan::GetMilliSecond()
	{
		return m_Time.millitm;
	}

	void TimeSpan::SetTime(unsigned long p_Seconds, unsigned short p_MilliSeconds)
	{
		Tick();
		m_Time.time = p_Seconds;
		m_Time.millitm = p_MilliSeconds;
	}
}
